#include "factory.h"

Factory::Factory()
{

}
const uint16 kCategoryGround = 0x0002;
b2World* Factory::createWorld(){
    b2World* w=new b2World(b2Vec2(0.0f,-1000.0f));
    b2BodyDef groundBodyDef;

    groundBodyDef.position.Set(0.0f, -80.0f);
//    wallLeftDef.position.Set(0,-50);
    b2Body* ground = w->CreateBody(&groundBodyDef);
//    b2Body* wall1=w->CreateBody(&wallLeftDef);
    b2PolygonShape groundBox;

    b2FixtureDef groundFixture;
    groundBox.SetAsBox(1000.0f, 30.0f);
    groundFixture.shape=&groundBox;
//    wallBox.SetAsBox(1.0f,50.0f);
//    groundFixture.isSensor=false;
    ground->CreateFixture(&groundFixture);
//    wall1->CreateFixture(&wallBox,0.0f);
    ground->SetName("ground");
//    b2Filter filter;
//    filter.categoryBits=kCategoryGround;
//    ground->GetFixtureList()->SetFilterData(filter);
    b2PolygonShape wallBoxLeft;
    b2BodyDef wallLeftDef;
    wallLeftDef.position.Set(0,-30);
    wallBoxLeft.SetAsBox(0.05f,60.0f);
    b2Body *wallLeft=w->CreateBody(&wallLeftDef);
    b2FixtureDef wallLeftFixture;
    wallLeftFixture.shape=&wallBoxLeft;
    wallLeft->CreateFixture(&wallLeftFixture);
    wallLeft->SetName("walll1");

    b2PolygonShape wallBoxRight;
    b2BodyDef wallRightDef;
    wallRightDef.position.Set(95,-30);
    wallBoxRight.SetAsBox(0.05f,60.0f);
    b2Body *wallRight=w->CreateBody(&wallRightDef);
    b2FixtureDef wallRightFixture;
    wallRightFixture.shape=&wallBoxRight;
    wallRight->CreateFixture(&wallRightFixture);
    wallRight->SetName("wall2");

    return w;
}
const uint16 kCategoryPlayer = 0x0001;
const uint16 kCategoryArea = 0x0003;
b2Body* Factory::createPlayerBody(b2World *world, QString name,float posX,float posY){
    b2BodyDef bodyDef;
    bodyDef.type = b2_dynamicBody;
    bodyDef.position.Set(posX, posY);
    b2Body* body = world->CreateBody(&bodyDef);
    b2PolygonShape dynamicBox;
    dynamicBox.SetAsBox(1.0f, 4.0f);
    b2FixtureDef fixtureDef;
    fixtureDef.shape = &dynamicBox;
    fixtureDef.density = 0.8f;
    fixtureDef.friction = 0.3f;
//    fixtureDef.isSensor=true;
//    fixtureDef.filter.categoryBits=kCategoryPlayer;
//    fixtureDef.filter.maskBits=kCategoryGround;
    b2Fixture *f=body->CreateFixture(&fixtureDef);
//    b2PolygonShape shape2;
//    shape2.SetAsBox(0.5f, 0.5f);
//    b2FixtureDef fixtureDef2;
//    fixtureDef2.shape = &shape2;
//    fixtureDef2.density = 1.0f;
//    fixtureDef2.filter.categoryBits=kCategoryArea;
//    fixtureDef2.filter.maskBits=kCategoryArea;
//    fixtureDef2.isSensor=true;
//    body->CreateFixture(&fixtureDef2)->RayCast();
    body->SetName(name.toStdString());
    return body;
}


